import { ADD_LIST, TOGGLE_STATE  } from '../action/actionTypes' 

const lists = (state=[], action) => {
    switch (action.type) {
        case ADD_LIST:
            return [
                ...state,
                {
                    id: action.id,
                    text: action.text,
                    completed: false
                }
            ]
        case TOGGLE_STATE:
            return state.map(list => {
                return list.id === action.id ? { ...list, completed: !list.completed} : list
            })
        default:
            return state
    }
}
export default lists